home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / DEV / I-Z / XLisp_1.6.cpt / StepLib.LSP < prev    next >
Lisp/Scheme  |  1985-04-27  |  3KB  |  91 lines

  1. ;+
  2. ;           STEPLIB: A library of useful functions needed by the STEP 1.0
  3. ;                       debugging tool.
  4. ;-
  5.  
  6. ;+
  7. ; autoload
  8. ;   Load a large function when it's called for the first time. After loading
  9. ;   the function then call it with whatever parameters were specified in the
  10. ;   first time call.
  11. ; format
  12. ;   (autoload name file)
  13. ;       name - name of function to autoload.
  14. ;       file - filename of file which contains function.
  15. ;-
  16. (defmacro autoload (name file) 
  17.     `(defun ,name (&rest rest) (load (etoa ',file)) (apply ,name rest) ))
  18.  
  19. ;+
  20. ; case
  21. ;   Select an alternative based on the value of a selector. 
  22. ;
  23. ; format
  24. ;   (case <selector> [(<key>  [<action>]...)]... )
  25. ;       selector - an expression which will be evaluated to determine which
  26. ;                   action to perform.
  27. ;       key      - a quoted sexpr. If key matches the value of selector,
  28. ;                   the <action>s corresponding to this key are evaluated.
  29. ;       action   - an sexpr which will be evaluated if its key matches the
  30. ;                   value of the selector.
  31. ;       returns  - the value of the last action in the chosen list of actions.
  32. ;                  If no key matches the selector's value and if one of the 
  33. ;                  keys is 't', then the value of the last action in 't's 
  34. ;                  actions. If no catchall 't' is present then returns nil.
  35. ;-
  36. (defun case (selector &rest options)
  37.    (do* ((restl options (cdr restl)) (result nil))
  38.         ((let ((label (caar restl)))
  39.              (cond ((or (equal selector label)
  40.                         (eq t label) )
  41.                            (setq result (cdar restl)) )
  42.                    (t (null restl)) ) )
  43.         (eval (rplacd '(progn) result)) ) ) )
  44.  
  45.  
  46. ;+
  47. ; etoa
  48. ;   Convert expression to ascii string.
  49. ;
  50. ; format
  51. ;   (etoa <expr>)
  52. ;       <expr> - an expression whose value print string will be returned.
  53. ;-
  54. (defun etoa (symbol) (apply 'strcat (mapcar 'chr (explode symbol))))
  55.  
  56. ;+
  57. ; short-princ
  58. ;   Print an s-expression using princ, but don't print out the contents
  59. ;       of nested lists. Instead print (...).
  60. ;
  61. ; format
  62. ;   (short-princ <expr>)
  63. ;       <expr> an expression whose value will be short-printed.
  64. ;-
  65. (defun short-princ (sexpr)
  66.     (cond ((consp sexpr)
  67.              (princ "(")
  68.              (dolist (item sexpr)
  69.                      (if (consp item)
  70.                          (princ "(...)")
  71.                          (princ item) )
  72.                      (princ " ") )
  73.              (princ ")") )
  74.           (t (princ sexpr)) ) )
  75.  
  76. ;+
  77. ; spaces
  78. ;   Print out some spaces.
  79. ;
  80. ; format
  81. ;   (spaces <num> [<sink>])
  82. ;       <num> - number of spaces to print to the sink.
  83. ;       <sink>- the output sink (defaults to standard output)
  84. ;-
  85. (defun spaces (n &optional sink)
  86.     (cond ((null sink)(setq sink *standard-output*)))
  87.     (dotimes (count n t)
  88.                 (write-char 32 sink) ) )
  89.  
  90.